package com.ruoyi.aiTool.aiConfig;


import com.ruoyi.aiTool.agent.SimpleQuestionAgent;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenAIConfig {

    @Value("${openai.api-key}")
    private String openAiApiKey;

    @Value("${openai.base-url}")
    private String baseUrl;

    @Value("${openai.model}")
    private String model;

    @Bean
    public OpenAiChatModel openAiChatModel() {
        return OpenAiChatModel.builder()
                .apiKey(openAiApiKey)
                .baseUrl(baseUrl)
                .modelName(model)
                .temperature(1.2)
                .build();
    }
    @Bean
    public SimpleQuestionAgent simpleQuestionAgent(OpenAiChatModel chatModel) {
        return AiServices.builder(SimpleQuestionAgent.class)
                .chatLanguageModel(chatModel)          // 使用前面定义的 OpenAI 模型
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10)) // 可选：对话记忆，保留最近 10 轮

                .build();
    }
}
